﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace API.Models.Repository
{
    public class IncomingInvoices_Repository : GenericRepository<PartnerDbContext, V_IncomingInvoices>
    {
        public override IQueryable<V_IncomingInvoices> Find(System.Linq.Expressions.Expression<Func<V_IncomingInvoices, bool>> predicate)
        {
            /// Получить данные
            IQueryable<V_IncomingInvoices> query = _entities.V_IncomingInvoices
                .Include("COMPANY")
                .Include("CUSTOMER")
                .Include("LOCATION")
                .Include("LINES")
                .Include("LINES.ITEM");

            /// Фильтрация по заданному условию
            if (predicate != null)
                query = query.Where(predicate);

            if (session != null)
                query = query
                    .Where(r => r.CUSTOMER_GUID == session.COMPANY_GUID);

            return query.AsQueryable();
        }
    }
}